
#pragma once

#include"QueueItem.h"


template<typename Type> class Queue
{

public:

	Queue()
		:head(0),tail(0)
	{

	}
	Queue(const Queue& Q)
		:Queue()
	{
		copy_elems(Q);
	}
	~Queue()
	{
		destory();
	}


public:

	void pop()
	{
		QueueItem<Type>* p =head;
		head=head->next;
		delete p;
	}

	void push(const Type& Q)
	{

		QueueItem<Type>* qItem=new QueueItem<Type>(Q);

		if(empty())
		{
			head=tail=qItem;
		}
		else
		{
			tail->next=qItem;
			tail=qItem;
		}

	}

	Type& front()
	{
			return head->item;
	}

	bool empty() const
	{
		return head==NULL;
	}




private:

	void destory()
	{
		while(!empty())
		{
			pop();
		}
	}

	void copy_elems(const Queue& q)
	{
		for (QueueItem<Type>* pt =q.head; pt; pt=pt->next)
		{
			push(pt->next);
		}
	}

private:

	QueueItem<Type>* head;
	QueueItem<Type>* tail;


	

};



